<template>
  <div class="mylike" v-if="likeGoods">
    <my-header title="我的喜欢">
      <template #right>
        <slot name="right"> &nbsp; </slot>
      </template>
    </my-header>

    <div class="wrap">
      <div class="content" v-for="(l, i) in this.likeGoods" :key="i">
        <van-card
          :title="l.name"
          :thumb="l.img[0]"
          :desc="'「' + l.ipRightList[0].ipRightName + '」'"
          @click="gotoDetail(l.itemsId)"
        >
          <template #tags>
            <van-tag plain type="danger">{{ l.itemTags[0].name }}</van-tag>
          </template>
        </van-card>
      </div>
    </div>

    <!-- footer -->
    <div class="footer" v-if="isHeight">
      <span class="">快去添加喜欢的商品吧~</span>
      <img src="@/assets/images/hutao.png" alt="" />
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 喜欢的商品列表
      likeGoods: [],
      // 是否显示底部嘉然
      isHeight: true,
    };
  },
  methods: {
    //   跳转到详情页
    gotoDetail(itemsId) {
      this.$router.push({ name: "detail", query: { itemsId: itemsId } });
    },
    //   获取当前id喜欢的商品的id
    async getLikeGid() {
      let res = await this.$ajax.checkLikeStatusData({
        phone: this.userInfo.phone,
        like: true,
      });
      // console.log(res);
      // let gidArr = []
      // res.forEach(item=>{
      //     gidArr.push(item.gid)
      // })
      // console.log(gidArr);

      res.forEach((item) => {
        this.$ajax
          .getGoodDetailData({
            itemsId: item.gid,
          })
          .then((result) => {
            // console.log(result);
            this.likeGoods.push(result.data);
          });
      });
      if (this.likeGoods.length > 3) {
        this.isHeight = false;
      }
      console.log(this.likeGoods);
      console.log(this.likeGoods.length);

      // 待处理---------------------------
      // length打印错误
    },
    // // 通过gid获取商品信息
    // async getLikeGoodDetailByGid(itemsId){
    //     let res = await this.$ajax.getGoodDetailData({
    //         itemsId:itemsId
    //     })
    //     console.log('商品信息',res);
    // }
  },
  mounted() {
    this.getLikeGid();
  },
};
</script>

<style lang="scss" scoped>
.mylike {
  width: 100%;
  .wrap {
    .content {
      border-top: 5px solid rgba($color: #ff99b1, $alpha: 0.3);
      .pswrap {
        display: flex;
        justify-content: space-between;
        .pxc {
          margin-left: 115px;
          font-size: 14px;
          color: #ff80aa;
          b {
            font-size: 12px;
          }
        }
      }
    }
  }
  .footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    span {
      color: #ff80aa;
      text-shadow: 2px 0 1px #ccc;
      font-size: 20px;
    }
    img {
      width: 50%;
    }
  }
}
</style>